package lz.com.demo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(value = "Hello 测试 和 redis测试")
public class Demo1 {
    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation(value="Hello lz 测试", notes="无注意事项")
    @RequestMapping(value = "/testHello",method = RequestMethod.POST)
    public String testHello() {
        return "Hello lz";
    }

    @ApiOperation(value="Hello lz 2 测试", notes="无注意事项")
    @RequestMapping(value = "/testHello2",method = RequestMethod.POST)
    public String testHello2() {
        return "Hello lz 2";
    }

    @ApiOperation(value="Hello lz 3 测试", notes="无注意事项")
    @RequestMapping(value = "/testHello3",method = RequestMethod.POST)
    public String testHello3() {
        return "Hello lz 3";
    }

    @ApiOperation(value="Hello lz 4 测试", notes="无注意事项")
    @RequestMapping(value = "/testHello4",method = RequestMethod.POST)
    public String testHello4() {
        return "Hello lz 4";
    }

    @ApiOperation(value="redis 测试", notes="无注意事项")
    @RequestMapping(value = "/redisTest",method = RequestMethod.POST)
    public String testRedis() {
        //设置值到redis
        redisTemplate.opsForValue().set("name", "lucy");
        //从redis获取值
        return (String) redisTemplate.opsForValue().get("name");
    }

    @ApiOperation(value="redis 测试", notes="redis中要有key k1 且有value值")
    @RequestMapping(value = "/redisGet",method = RequestMethod.POST)
    public String testRedisGet() {
        return (String) redisTemplate.opsForValue().get("k1");
    }

}
